package com.heima.day2.test10;

import java.util.ArrayList;
import java.util.Scanner;

public class ShopTest {
    public static void main(String[] args) {
        ArrayList<Product> arrayList = new ArrayList<>();
        Product b = new Product(1, "香蕉", 5, 4);
        Product a = new Product(2, "苹果", 3, 4);
        Product o = new Product(3, "橘子", 6, 4);

        b.showShop();
        a.showShop();
        o.showShop();
        System.out.println("输入0进行结账");
        int bn=0,an=0,on=0;
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入想要的商品id，按0结算");
            int s = sc.nextInt();
            if (s==1) {
                arrayList.add(b);
                b.setTotal(b.getTotal() - 1);
                bn++;
            }
            if (s==2) {
                arrayList.add(a);
                a.setTotal(a.getTotal() - 1);
                an++;
            }
            if (s==3) {
                arrayList.add(o);
                o.setTotal(o.getTotal() - 1);
                on++;
            }
            if (s==0) {
                break;
            }
            b.showShop();
            a.showShop();
            o.showShop();
            System.out.println("输入0进行结账,输入-号加第几个商品删除该商品");

            if (s<0){
                int index=(s*-1)-1;
                arrayList.remove(index);
            }
            System.out.println("==============================");;
            for (int i = 0; i < arrayList.size(); i++) {
                System.out.print(arrayList.get(i).getName()+"*1");
            }
            System.out.println();
            System.out.println("==============================");
        }
        double sum=0;
        for (int i = 0; i < arrayList.size(); i++) {
            if (arrayList.get(i).getId()==1){
                sum+=arrayList.get(i).getPrice() * bn;
            }
            if (arrayList.get(i).getId()==2){
                sum+=arrayList.get(i).getPrice() * an;
            }
            if (arrayList.get(i).getId()==3){
                sum+=arrayList.get(i).getPrice() * on;
            }
        }
        System.out.println("共"+sum+"元");
    }
}
